From: Yuan Fu Date: Thu, 13 Mar 2025 07:33:47 +0000 (-0700) Subject: Fix treesit-parser-create behavior regarding indirect buffers X-Git-Tag: archive/raspbian/1%30.2+1-2+rpi1^2~2^2~24^2~204 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=defc55bb6f954276a1cb9e3b5c50251ba5e5b40f;p=emacs.git Fix treesit-parser-create behavior regarding indirect buffers The previous fix fixed the problem that treesit-parser-create always use the current buffer, but that introduce another subtle problem: if an indirect buffer creates a parser, the parser saves the base buffer rather than the indirect buffer. In Emacs 29, if you create a parser in an indirect buffer, the parser saves the indirect buffer. This change of behavior breaks some existing use-cases for people using indirect buffer with tree-sitter. In Emacs 31, indirect buffers and base buffer get their own parser list, so this problem doesn't exist anymore. The fix is only for Emacs 30. * src/treesit.c (Ftreesit_parser_create): Use the buffer that's given to treesit-parser-create, even if it's an indirect buffer. --- diff --git a/src/treesit.c b/src/treesit.c index f234698defd..3a0e9674f65 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -1560,6 +1560,9 @@ an indirect buffer. */) CHECK_BUFFER (buffer); buf = XBUFFER (buffer); } + + struct buffer *buffer_given = buf; + if (buf->base_buffer) buf = buf->base_buffer; @@ -1595,7 +1598,7 @@ an indirect buffer. */) /* Create parser. */ Lisp_Object lisp_buf; - XSETBUFFER (lisp_buf, buf); + XSETBUFFER (lisp_buf, buffer_given); Lisp_Object lisp_parser = make_treesit_parser (lisp_buf, parser, NULL, language, tag);